package com.x.provider.api.general.enums;

import com.x.core.enums.IntegerEnum;

public enum ItemToggleRelationEnum implements IntegerEnum {
    NO_RELATION(-1),
    TRUE_RELATION(1),
    FALSE_RELATION(0)
    ;

    private Integer value;

    ItemToggleRelationEnum(Integer value){
        this.value = value;
    }

    @Override
    public Integer getValue() {
        return value;
    }

    public static ItemToggleRelationEnum valueOf(Integer relation){
        for (ItemToggleRelationEnum item: ItemToggleRelationEnum.values()) {
            if (item.getValue().equals(relation)){
                return item;
            }
        }
        return null;
    }

    public static ItemToggleRelationEnum valueOf(Boolean relation){
        if (relation == null){
            return NO_RELATION;
        }
        return relation ? TRUE_RELATION : FALSE_RELATION;
    }

    public static Boolean to(Integer relation){
        if (ItemToggleRelationEnum.NO_RELATION.getValue().equals(relation)){
            return null;
        }
        return ItemToggleRelationEnum.TRUE_RELATION.getValue().equals(relation) ? true : false;
    }
}
